<?php

namespace Cck\ArticlesSystem\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class SettingGroupResource extends JsonResource
{
    public function toArray($request)
    {
        if (!$this->resource) {
            return [];
        }

        $result = $this->resource->toArray();

        $result['settings'] = $this->whenLoaded('settings', function () {
            return SettingResource::collection($this->resource->settings->sortByDesc('order')->values());
        });

        return $result;
    }
}
